package com.jsb.laundry.common.exception;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 通用返回类
 *
 * @param <T>
 */
@Data
@NoArgsConstructor
@ApiModel(value = "BaseResponse对象", description = "接口统一返回数据格式")
public class BaseResponse<T> implements Serializable {
    @ApiModelProperty(value = "响应状态码:200 表示成功", dataType = "string", example="200")
    private String code;
    @ApiModelProperty(value = "响应数据")
    private T data;
    @ApiModelProperty(value = "提示信息", dataType = "string")
    private String message;

    public BaseResponse(String code, T data, String message) {
        this.code = code;
        this.data = data;
        this.message = message;
    }

    public BaseResponse(String code, T data) {
        this(code, data, "");
    }

    public BaseResponse(ErrorCode errorCode) {
        this(errorCode.getCode(), null, errorCode.getMessage());
    }
}
